define(function(require) {
    var $= require("lib/zepto");
	var Zepto = require("lib/zepto");
    var winDialog = require("lib/winDialog");
    var Dialog = require("./dialog");
    $(function() {
		
		// 锦囊跳动
		var jn_timer = 0;
		var jnwidth = $(".jinnang").width();
		setInterval(function(){
			if(jn_timer>50){
				jn_timer = 0;
			}
			if(jn_timer<10){
				$(".jinnang").css({"width":(2+Math.sin(jn_timer)/jnwidth)+"rem"});
			}
			jn_timer++;
		},100);
		//jinnang带动画，jin-nang不带动画。
		$(".jinnang,.jin-nang").on("click",function(){
			$(".poupFadIn").show();
		});
	
		// 锦囊菜单
		$(".poupClose").on("click",function(){
			$(".poupFadIn").hide();
		});
		$(".poupTitleMune").on("click",function(){
			var id = $(this).attr("id");
			$(".poupMain").hide();
			$(".awardBox").hide();
			switch(id){
				case "actionExpBtn":
					$(".slideBarTip").css({"left":".6rem"});
					$("#ruleBox").show();
				break;
				case "ranBtn":
					$(".slideBarTip").css({"left":"5rem"});
					$("#rankBox").show();
				break;
				case "prizeBtn":
					$(".slideBarTip").css({"left":"9.6rem"});
					$("#awardBox,.awardBox").show();
					$(".awardBox").show();
				break;
				case "giftBtn":
					$("#giftBtn").css({"background":"rgba(0,0,0,0.5)"});
					$("#medalBtn").css({"background":""});
					$(".giftBox").show();
					$(".awardBox").show();
				break;
				case "medalBtn":
					$("#giftBtn").css({"background":""});
					$("#medalBtn").css({"background":"rgba(0,0,0,0.5)"});
					$(".medalBox").show();
					$(".awardBox").show();
				break;
			}
		});
		var options = {
				"c":"index",
				"m":"shopmobile",
				"a":"ajax_get_user_info",
				"tida_mixnick":APP.mixnick,
				"eid":APP.eid,
				"sid":APP.sid
			};
		$(".loading").on("click",function(){
			Tida.toast("请稍后，正在为您准备金蛋...");
		});
		var follow = function(){
			Tida.social({
				sellerId: APP.sellerUid,
				action: "follow"
			}, function (e) {
				if(e.errorCode){
					$(".coll_msg").text(e.data+e.errorMsg);
					$(".collect").show();
					$(".collect").on("click",function(){
						follow();
					});
				}else{
					var options = {
							"a":"collect_shop",
							"tida_mixnick":APP.mixnick,
							"eid":APP.eid
						};
					$.getJSON(APP.urls.user,options,function(re){});
					$(".collect").hide();
					Tida.toast("您已成功收藏店铺");
				}
			});
		}
		$.getJSON(APP.urls.base_url,options,function(re){
			if(re.hasError){
				alert("读取用户信息出错");
			}else{
				$(".loading").hide();
				APP.shop_uid=re.user_info.shop_uid;
				APP.sys_uid=re.user_info.sys_uid;
				APP.point = parseInt(re.user_info.seeds);
				APP.chance = parseInt(re.user_event_info.score);
				APP.followed=re.user_event_info.collect; //存储是否已关注店铺
				APP.eventUid=re.id;
				APP.urls.win+="&shop_uid="+APP.shop_uid;
				APP.urls.exchange+="&shop_uid="+APP.shop_uid;
				APP.urls.mission+="&shop_uid="+APP.shop_uid;
				APP.urls.signday+="&shop_uid="+APP.shop_uid;
				APP.urls.signpassday+="&shop_uid="+APP.shop_uid;
				APP.urls.signlingjiang+="&shop_uid="+APP.shop_uid;
				APP.urls.gift+="&shop_uid="+APP.shop_uid;
				APP.urls.user+="&shop_uid="+APP.shop_uid;
				$("#J_Seeds").text(APP.point); //设置积分
				$("#J_Times").text(APP.chance); //设置抽奖次数
				var html="";
				var html_in_jinnang="";
				var html_gift="";
				var mygifts = re.user_event_info.mygifts;
				for(var gift=0;gift<mygifts.length;gift++){
					var tmp="";
					tmp+="<tr><td>"+mygifts[gift].actiontime+"</td>";
					tmp+="<td>"+mygifts[gift].gift_name+"</td>";
					var params="";
					for(var prm in mygifts[gift].param){
						params+=prm+"=\""+mygifts[gift].param[prm]+"\" ";
					}
					params+=" data-mygid=\""+mygifts[gift].id+"\"";
					params+=" data-gid=\""+mygifts[gift].giftid+"\"";
					params+=" data-gtype=\""+mygifts[gift].gtype_code+"\"";
					tmp+="<td><input type=\"button\" class=\"js-myg"+mygifts[gift].id+"\" "+params +" /></td></tr>";
					html=tmp+html;
					
				}
				$(".win-table").html(html);
				
				for(var gift=0;gift<mygifts.length;gift++){
					var tmp="";
					tmp+='<div class="codeInfoBox">';
					tmp+='<div class="djqImgBox"><img src="'+mygifts[gift].gift_pic_url+'_200x200.jpg"/></div>';
					tmp+='<div class="isEmptyAward ellipsis">'+mygifts[gift].gift_name+'</div>';
					//<!--div class="codeperiod" style="margin: 0.25rem 0.6rem;"><span>兑奖期限</span>：2016.07.20 至 2016.07.27</div-->
					//tmp+='<div class="goDetailIcon">'+medal[m].get_time+'</div>';
					tmp+='<div class="awardWrap"></div>';
					
					var params="";
					for(var prm in mygifts[gift].param){
						params+=prm+"=\""+mygifts[gift].param[prm]+"\" ";
					}
					params+=" data-mygid=\""+mygifts[gift].id+"\"";
					params+=" data-gid=\""+mygifts[gift].giftid+"\"";
					params+=" data-gtype=\""+mygifts[gift].gtype_code+"\"";
					
					tmp+="<div class=\"buttons\"><input type=\"button\" class=\"js-myg"+mygifts[gift].id+"\" "+params +" /></div>";
					tmp+='</div>';
					html_gift = tmp+html_gift;
				}
				$("#giftAward").html(html_gift);
				
				var medal = re.user_event_info.medal;
				for(var m=0;m<medal.length;m++){
					var tmp="";
					tmp+='<div class="codeInfoBox">';
					tmp+='<div class="djqImgBox"><img src="'+medal[m].pic_url+'_100x100.jpg"/></div>';
					tmp+='<div class="isEmptyAward ellipsis">奖章：'+medal[m].title+'</div>';
					//<!--div class="codeperiod" style="margin: 0.25rem 0.6rem;"><span>兑奖期限</span>：2016.07.20 至 2016.07.27</div-->
					//tmp+='<div class="goDetailIcon">'+medal[m].get_time+'</div>';
					tmp+='<div class="awardWrap"></div>';
					tmp+='<div class="buttons"><input type="button" value="数量：'+medal[m].medal_num +'个" /></div>';
					tmp+='</div>';
					html_in_jinnang = tmp+html_in_jinnang;
				}
				$("#awardInfo").html(html_in_jinnang);
				if(APP.mustFollow && APP.followed==0){
					$(".collect").show();
					follow();
				}
			}
		});
    });
	var curtool = $(".curtool").val();
	switch(curtool){
		case "mob_eggs":
			var Egg = require('./egg');
			var cEgg = new Egg();
			break;
		case "mob_shake":
		//监听摇一摇
			var Shake = require('./shake');
			var cShake = new Shake();
			break;
		case "mob_wheel":
		case "mob_dices":
		//监听大转盘和九宫格
			var DicesWheel = require('./dices_wheel');
			var cDicesWheel = new DicesWheel();
			for(var i=0;i<8;i++){
				$(".gift_cover"+i).hide();
			}
			$(".btn_nostart").hide();
			break;
	}

});